<script lang="ts" setup>
import config from '../../../../config'
import { Role, roleList } from '../../../../enums/Role'

const props = defineProps<{
  dataList: WxUser[],
  loading: boolean
}>()
const roles: any[] = roleList
</script>

<template>
  <el-table
      border
      stripe
      v-model:data="props.dataList"
      table-layout="auto"
      v-loading="loading"
      style="width: 100%"
      height="500px">
    <el-table-column
        prop="nick_name"
        label="昵称"
        align="center"
        width="200"
    />
    <el-table-column
        label="头像"
        align="center"
        width="160"
    >
      <template #default="scope">
        <el-avatar
            :src="config.baseUrl + '/' + scope.row.avatar"
        />
      </template>
    </el-table-column>
    <el-table-column
        prop="phone"
        label="手机号码"
        align="center"
    />
    <el-table-column
        label="角色"
        align="center"
        width="160"
    >
      <template #default="scope">
        <el-tag>{{ roles.find((item: Role) => item.value === scope.row.role).label }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column
        label="创建时间"
        align="center"
        width="160"
    >
      <template #default="scope">
        {{ new Date(scope.row.createdAt).toLocaleString('zh-CN') }}
      </template>
    </el-table-column>
    <el-table-column
        label="经纪人天数"
        align="center"
        width="160"
    >
      <template #default="scope">
        {{ scope.row.broker_time !== null ? Math.floor((new Date().getTime() - new Date(scope.row.broker_time).getTime()) / (1000 * 60 * 60 * 24)) + '天' : '无' }}
      </template>
    </el-table-column>
  </el-table>
</template>

<style lang="less" scoped>

</style>
